<!DOCTYPE html>
<html lang="en">
<head>
    <title>朝圣"菱"距离</title>
    <meta charset="UTF-8">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> -->
    
    
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
    <link rel="stylesheet" type="text/css" href="css/example.css"/>
    <link rel="stylesheet" type="text/css" href="css/animate.css"/>
    <link rel="stylesheet" type="text/css" href="css/sweet-alert.css"/>
    
    
    <script type="text/javascript" src="../js/jquery-1.7.2-min.js"></script>
    
    <script type="text/javascript" src="js/media.js"></script>
    <script type="text/javascript" src="js/sweet-alert.js"></script>
	<script type="text/javascript" src="../js/common/common.js"></script>
	<script type="text/javascript" src="../js/common/wechatCommon.js"></script>
	
</head>

<!--移动端版本兼容 -->

<body>
	<div class="page">
		<div class="content">
            <div class="title"></div>
            <div class="inner">
                <div class="cities"></div>
                <div class="prompt">
                   	 温馨提示:本场秒获的券需在2017年08月10日前激活 
                </div>
                <div class="activity clearfix">
                    <div class="daojishi lf">
                        <span class="text">秒杀倒计时</span>
                        <span class="time">00:00:00</span>
                    </div>
                    <div class="miaosha rt">
                    	<div class="arrow animated bounceInDown"></div>
                    </div>
                </div>
                <div class="rules">
                    <div class="rules_content">
                        <span>1.秒杀：</span>2017/07/25-2017/08/20每日10:00、16:00整点秒杀900元现金电子抵用券；
                    </div>
                    <div class="rules_content">
                        <span>2.激活：</span>获得900元现金抵用券的车主需在指定期限内上传人车、驿站名的合影1张，审核通过后即可激活该券;
                    </div>
                    <div class="rules_content">
                        <span>3.使用（2选1）：</span>已激活的900元现金抵用券可在全国认证的任意广汽三菱4S店消费使用或兑换丽江驿站免费住宿3晚。
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script type="text/javascript">
    
    	var rootPath = getRootPath();
    	
    	$(document).ready(function(){
    		init();
		});
    	
    	function init(){
    		$.ajax({
				headers:{'Cookie':document.cookie},
				type:"POST", 
		        url:rootPath + "/pointActivity/api/v1/goToLhasaInit",
		        //url : "http://localhost:9013/pointActivity/api/v1/goToLhasaInit",
		        dataType:"json",
		        contentType:"application/json",
		        success:function(data){
		        	$(".prompt").html("温馨提示:本场秒获的券需在" + data.activationEndDate + "前激活 ");
		        	var resultType = data.INIT_RESULT_TYPE;
		        	if(0 == resultType){
		        		luckDrawInit();
		        		return ;
		        	} else if(1 == resultType){
		        		swal("只有车主才可以参加活动.请在个人中心进行会员注册及车辆认证");
		        		bindMiaoButton(resultType);
		        		return ;
		        	} else if(2 == resultType){
		        		window.location.href = rootPath + "/views/jq.html";
		        	} else if(3 == resultType){
		        		luckDrawInit();
		        		return ;
		        	} else if(4 == resultType){
		        		swal("您有一张奖券已过期.");
		        		luckDrawInit();
		        	} else if(5 == resultType){
		        		swal("秒杀活动还未开始");
		        		bindMiaoButton(resultType);
		        		return ;
		        	} else if(6 == resultType){
		        		swal("秒杀活动已结束");
		        		bindMiaoButton(resultType);
		        		return ;
		        	} else if(7 == resultType){
		        		swal("朝圣\"菱\"距离活动已结束");
		        		bindMiaoButton(resultType);
		        		return ;
		        	}
		        }
		     });
    	}
    	
    	function bindMiaoButton(resultType){
    		$(".miaosha.rt").unbind().bind("click",function(){
    			myAlert(resultType);
    		});
    	}
    	
    	function myAlert(type){
    		if(1 == type){
	    		swal("只有车主才可以参加活动.请在个人中心进行会员注册及车辆认证");
    		} else if(7 == type){
        		swal("朝圣\"菱\"距离活动已结束");
        	} else if(6 == type){
        		swal("秒杀活动已结束");
        	} else if(5 == type){
        		swal("秒杀活动还未开始");
        	}
    	}
    	
    	var seconds = 0;
    	
    	function luckDrawInit(){
    		$.ajax({
    			headers: {'Cookie' : document.cookie },
    			type:"POST", 
		        url:rootPath + "/pointActivity/api/v1/luckDrawInit",
		        //url : "http://localhost:9013/pointActivity/api/v1/luckDrawInit",
		        dataType:"json",
		        contentType:"application/json",               
		        success:function(data){
		        	if(data.SeckillIn){
		        		$(".text").text("秒杀倒计时:");
		        		$(".arrow").show();
		        		$(".miaosha.rt").unbind().bind("click",function(){
		        			luckDraw();
		        		});
		        	} else {
		        		$(".text").text("距离下一场:");
		        		$(".arrow").hide();
		        		$(".miaosha.rt").unbind().bind("click",function(){
		        			unLuckDraw();
		        		});
		        	}
		        	seconds = data.SeckillSurplusTime;
		        	countDown(seconds);
		        }
		     });
    	}
    	
    	function unLuckDraw(){
    		swal("距离下一场还有" + $(".time").text());
    	}
    	
       	var t = 0;
        function countDown(seconds) {
            $(".time").html(formatTime(seconds));
            var timer = setTimeout("countDown(seconds--)", t);
            t = 1000;
            if (seconds == 0) {
                clearTimeout(timer);
                init();
            }
        }
        

        function formatTime(longTime){
          var time = parseFloat(longTime);
          if (time != null && time != ""){
              if (time < 60) {
                  var s = time;
                  s < 10 && (s = "0" + s);
                  time = "00:00:" + s;
              } else if (time > 60 && time < 3600) {
                  var m = parseInt(time / 60);
                  m < 10 && (m = "0" + m);
                  var s = parseInt(time % 60);
                  s < 10 && (s = "0" + s);
                  time = "00:" + m + ":" + s;
              } else if (time >= 3600 && time < 86400) {
                  var h = parseInt(time / 3600);
                  h < 10 && (h = "0" + h);
                  var m = parseInt(time % 3600 / 60);
                  m < 10 && (m = "0" + m);
                  var s = parseInt(time % 3600 % 60 % 60);
                  s < 10 && (s = "0" + s);
                  time = h + ":" + m + ":" + s;
              } else if (time >= 86400) {
                  var d = parseInt(time / 86400);
                  d < 10 && (d = "0" + d);
                  var h = parseInt(time % 86400 / 3600);
                  h < 10 && (h = "0" + h);
                  var m = parseInt(time % 86400 % 3600 / 60);
                  m < 10 && (m = "0" + m);
                  var s = parseInt(time % 86400 % 3600 % 60 % 60);
                  s < 10 && (s = "0" + s);
                  time = h + ":" + m + ":" + s;
              }
          }
          return time;   
        }


        
    	function luckDraw(){
    		$(".miaosha.rt").unbind();
	   		$.ajax({
				headers: {'Cookie' : document.cookie },
				type:"POST", 
		        url:rootPath + "/pointActivity/api/v1/luckDraw",
		        //url : "http://localhost:9013/pointActivity/api/v1/luckDraw",
		        dataType:"json",
		        contentType:"application/json",
		        success:function(data){
		        	if(data.hasOwnProperty("insertNum")){
		        		if(1 == data.insertNum){
			        		window.location.href = rootPath + "/views/jq.html?isInit=false";
			        	} else {
			        		window.location.href = rootPath + "/views/failed.html";
			        	}
		        	} else {
		        		swal(data.errMsg);
		        	}
		        }
		     });
    	}
    	
    </script>
</body>
</html>